package com.example.zjm.fragmentdome;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.HashMap;
import java.util.List;

public class Fragment02 extends Fragment {

    private ListView listView;
    private SimpleAdapter simpleAdapter;
    //存放显示数据的集合
    private List<HashMap<String, Object>> list;



    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    //初始化布局
    View view = inflater.inflate(R.layout.fragment02,null);
    //初始化listview
    listView = view.findViewById(R.id.lv_img_name);
    //获取显示数据集合
    list =DataSource.getData();
    //显示数据信息在集合中的key
    String[] from = {"img_id", "name"};
    //显示信息的控件id
    //注意form和to中的key和id顺序必须一一对应
    int[] to = {R.id.img_head, R.id.tv_frendname};
    //初始化simpleAdapter
    simpleAdapter = new SimpleAdapter(getContext(), list, R.layout.lv_img_item, from, to);
    //为listview设置adapter
    listView.setAdapter(simpleAdapter);











        return view;
    }
}
